package com.picture.wallpaper.core.utils;

import com.picture.wallpaper.dao.dto.PictureDownloadDto;
import com.picture.wallpaper.dao.vo.EncipherPictureDownloadVo;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class TypeUtils {
    @Autowired
    private AES aes;
    @Autowired
    private PictureDownloadDto pictureDownloadDto;
//    Date date=new Date();
//    String questTime=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
    @ApiModelProperty("EncipherPictureDownloadVo转pictureDownloadDto")
    public PictureDownloadDto typeConversion(EncipherPictureDownloadVo encipherPictureDownloadVo){
        String pictureId= aes.decrypt(encipherPictureDownloadVo.getEncipherPictureId());
        String pictureName=aes.decrypt(encipherPictureDownloadVo.getEncipherPictureName());
        pictureDownloadDto.setPictureId(Integer.parseInt(pictureId));
        pictureDownloadDto.setPictureName(pictureName);
        pictureDownloadDto.setPictureNumber(encipherPictureDownloadVo.getEncipherPictureNumber());
        return pictureDownloadDto;
    }

    @ApiModelProperty("对象转list")
    public  <T> List<T> objectToList(Object obj, Class<T> cla){
        List<T> list=new ArrayList<T>();
        if(obj instanceof ArrayList<?>){
            for (Object o: (List<?>) obj){
                list.add(cla.cast(o));
            }
            return list;
        }
        return null;
    }
    @ApiModelProperty("Object转对象")
    public PictureDownloadDto objectToPictureDownloadDto(Object obj){
            return  pictureDownloadDto.getClass().cast(obj);
    }
}
